<template>
    <el-select v-model="value" placeholder="请选择" style="width: 100%;" @change="handleChange" :clearable="disabled">
              <el-option
                v-for="item in orientationList"
                :key="item.directionId"
                :label="item.directionName"
                :value="item.directionName">
              </el-option>
            </el-select>
</template>
<script>
import api from "common/src/api/election/honorCourse"
import UTILS from "common/src/utils/utils";
export default {
  name: "OrientationSelect",
  props: {
    moduleId:{default: ''},
    disabled:{default: true}
  },
  data() {
    return {
      orientationList: [],
      module: '',
      value: ''
    }
  },
  watch:{
      moduleId: {
          handler(newVal, oldVal) {
            if(UTILS.isNotEmpty(newVal)){
              if(!_.isEqual(newVal, oldVal)) {
                  this.module = newVal;
                  this.search();
              }
            } else {
              this.value = ''
              this.orientationList = []
            }
        }
      }
  },
  methods: {
      handleChange(val) {
        this.$emit("input", val);
        this.$emit('change', val)
      },
      search() {
          api.honorDirectionList(this.module).then(res =>{
              this.orientationList = res;
              console.log(res)
          })
      }
  }
}
</script>